package chanfoofoo;

import com.google.gdata.client.calendar.*;
import com.google.gdata.data.*;
import com.google.gdata.data.calendar.*;
import com.google.gdata.data.extensions.*;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;


public class sms_google {
	static String google_time(GregorianCalendar in_Date) { // 2009-12-29T15:00:00+08:00
		String result = null ;  		 				
		Calendar new_time = (Calendar) in_Date.clone() ;   
		new_time.add(GregorianCalendar.MINUTE , +10) ;
		String time_zone = String.format(Locale.UK, "%1$tz" , new_time).substring(0, 3) + ":00" ; 
    	result =  String.format(Locale.UK, "%1$tY-%1$tm-%1$tdT%1$tH:%1$tM:00" , new_time) + time_zone ;
		return result ; 
	}
	
	public static String create_event(GregorianCalendar in_Date , String in_Title) {		
		CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
		try {
			myService.setUserCredentials("mcmymail@gmail.com", "mcmcmcmc");
			URL postUrl =
				  new URL("http://www.google.com/calendar/feeds/mcmymail@gmail.com/private/full");
				CalendarEventEntry myEntry = new CalendarEventEntry();

				myEntry.setTitle(new PlainTextConstruct(in_Title)) ; // ("Tennis with Beth"));			

				DateTime startTime = DateTime.parseDateTime(google_time(in_Date)) ; 
				DateTime endTime = DateTime.parseDateTime(google_time(in_Date));
				When eventTimes = new When();
				eventTimes.setStartTime(startTime);
				eventTimes.setEndTime(endTime);
				myEntry.addTime(eventTimes);
				
				Reminder reminder = new Reminder();
				reminder.setMinutes(5);
				reminder.setMethod(Reminder.Method.SMS);
				myEntry.getReminder().add(reminder);
				
				// Send the request and receive the response:
				CalendarEventEntry insertedEntry = myService.insert(postUrl, myEntry);
				return insertedEntry.toString() ; 
		} catch (Exception ex) {
			ex.printStackTrace() ; 
		}
		return "" ; 
	}
	public static void main(String[] args) {
		GregorianCalendar t1 = new GregorianCalendar(TimeZone.getTimeZone("Asia/Hong_Kong")) ;
		System.out.println(google_time(t1)) ;
		System.out.println(t1.getTime()) ;
	}
}
